home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / misc / pdflib / pdf.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  7KB  |  268 lines

  1. /* pdf.h
  2.  * Copyright (C) 1997-98 Thomas Merz. All rights reserved.
  3.  *
  4.  * PDFlib public declarations and definitions
  5.  */
  6.  
  7. #ifndef PDF_H
  8. #define PDF_H
  9.  
  10. #include <stdio.h>
  11. #include <stdarg.h>
  12.  
  13. #include "p_port.h"
  14.  
  15. #ifdef USE_TIFF
  16. #include "tiffio.h"
  17. #endif
  18.  
  19. #define PDFLIB_VERSION    "PDFlib V0.6 (C) Thomas Merz 1997-98"
  20.  
  21. /* default path to font and AFM directory */
  22. #ifndef PDF_DEFAULT_FONT_PATH
  23. #define PDF_DEFAULT_FONT_PATH    "./fonts"
  24. #endif
  25.  
  26. /* Data types and defines */
  27.  
  28. typedef unsigned char byte;
  29.  
  30. #define false    0
  31. #define true    1
  32.  
  33. /* Error and warning levels */
  34. #define PDF_INFO    1
  35. #define PDF_WARN    2
  36. #define PDF_FATAL    3
  37. #define PDF_INTERNAL    4
  38.  
  39. /* PDF version compatiblity modes */
  40. typedef enum { PDF1_0, PDF1_1, PDF1_2 } PDF_compat_mode;
  41.  
  42. typedef enum {
  43.     builtin, pdfdoc, macroman, macexpert, winansi, encoding_count
  44. } PDF_encoding;
  45.  
  46. typedef char *PDF_encodingvector[256];
  47.  
  48. typedef enum {
  49.     none, lzw, runlength, ccitt, dct, flate, compression_count
  50. } PDF_compression;
  51.  
  52. typedef enum {
  53.     trans_none, trans_split, trans_blinds, trans_box, 
  54.     trans_wipe, trans_dissolve, trans_glitter, trans_replace,
  55.     transition_count
  56. } PDF_transition;
  57.  
  58. typedef enum {
  59.     DeviceGray, DeviceRGB, DeviceCMYK, 
  60.     CalGray, CalRGB, Lab, 
  61.     Indexed, Pattern, Separation,
  62.     colorspace_count
  63. } PDF_colorspace;
  64.  
  65. typedef byte pdf_colormap[256][3];
  66.  
  67. typedef struct PDF_s PDF;
  68.  
  69. typedef struct {
  70.     float width, height;
  71. } PDF_pagesize;
  72.  
  73. /* Predefine some useful paper formats */
  74. extern PDF_pagesize
  75. a0, a1, a2, a3, a4, a5, a6, b5, letter, legal, ledger, p11x17;
  76.  
  77. typedef struct {
  78.     /* general stuff */
  79.     bool        binary_mode;
  80.     PDF_compat_mode    required_compatibility;
  81.     void
  82.         (*error_handler)(int level, const char* fmt, va_list ap);
  83.  
  84.     /* PDF Info dictionary entries */
  85.     char        *Keywords;
  86.     char        *Subject;
  87.     char        *ModDate;
  88.     char        *Title;
  89.     char        *CreationDate;
  90.     char        *Creator;
  91.     const char    *Producer;
  92.     char        *Author;
  93.  
  94.     /* path to font directory */
  95.     char        *fontpath;
  96. } PDF_info;
  97.  
  98. typedef struct { float a, b, c, d, e, f; } PDF_matrix;
  99.  
  100. /* not currently used */
  101. /* typedef struct { float x, y; } PDF_point; */
  102.  
  103. typedef struct PDF_data_source_s PDF_data_source;
  104.  
  105. struct PDF_data_source_s {
  106.     byte         *next_byte;
  107.     size_t        bytes_available;
  108.     void        (*init)(PDF *, PDF_data_source *src);
  109.     bool        (*fill)(PDF *, PDF_data_source *src);
  110.     void        (*terminate)(PDF *, PDF_data_source *src);
  111.  
  112.     byte        *buffer_start;
  113.     size_t        buffer_length;
  114.     byte        *private_data;
  115. };
  116.  
  117. struct PDF_image_t;
  118.  
  119. typedef struct PDF_image_t {
  120.     FILE        *fp;        /* image file pointer */
  121.     char        *filename;    /* image file name */
  122.     unsigned int    width;        /* image width in pixels */
  123.     unsigned int    height;        /* image height in pixels */
  124.     int            bpc;        /* bits per color component */
  125.     unsigned int    components;    /* number of color components */
  126.     PDF_compression    compression;    /* image compression type */
  127.     PDF_colorspace    colorspace;    /* image color space */
  128.     bool        indexed; /* image contains colormap (palette) */
  129.  
  130.     unsigned int    BitPixel;    /* HACK: use bpc instead */
  131.     pdf_colormap     colormap;
  132.  
  133.     /* JPEG specific stuff */
  134.     bool        adobe;        /* JPEG image with Adobe marker */
  135.     long        startpos;    /* start of image data in file */
  136.     float            dpi;        /* image resolution in dots per inch */
  137.  
  138. #ifdef USE_TIFF
  139.     /* TIFF specific stuff */
  140.     TIFF        *tif;        /* pointer to TIFF data structure */
  141.     uint32        *raster;    /* frame buffer */
  142.     int            cur_line;    /* current image line */
  143. #endif
  144.  
  145.     /* GIF specific stuff */
  146.     /*unsigned int    ColorResolution;*/
  147.     unsigned int    Background;
  148.     /*unsigned int    AspectRatio;*/
  149.  
  150.     int            transparent;
  151.     int            delayTime;
  152.     int            inputFlag;
  153.     int            disposal;
  154.  
  155.     int            useGlobalColormap;
  156.     unsigned int    bitPixel;
  157.  
  158.     bool        interlace;
  159.     int            imageno;
  160.  
  161.     int            no;        /* PDF image number */
  162.     PDF_data_source    src;
  163.     void        (*closefunc)(PDF *p, struct PDF_image_t *image);
  164. } PDF_image;
  165.  
  166. /* 
  167.  * ----------------------------------------
  168.  * Method prototypes, sorted by source file
  169.  * ----------------------------------------
  170.  */
  171.  
  172. /* p_basic.c */
  173. PDF_info *PDF_get_info(void);
  174. PDF *PDF_open(FILE *fp, PDF_info *info);
  175. void PDF_close(PDF *p);
  176. void PDF_begin_page(PDF *p, float height, float width);
  177. void PDF_end_page(PDF *p);
  178. void PDF_set_transition(PDF *p, PDF_transition t);
  179. void PDF_set_duration(PDF *p, float t);
  180. void *PDF_malloc(size_t size, char *caller);
  181. void PDF_free(void *mem);
  182.  
  183. /* p_text.c */
  184. void PDF_show(PDF *p, char *text);
  185. void PDF_show_xy(PDF *p, char *text, float x, float y);
  186. void PDF_set_font(PDF *p, char *fontname, float fontsize, PDF_encoding enc);
  187. void PDF_set_leading(PDF *p, float l);
  188. void PDF_set_text_rise(PDF *p, float rise);
  189. void PDF_set_horiz_scaling(PDF *p, float scale);
  190. void PDF_set_text_rendering(PDF *p, byte mode);
  191. void PDF_set_text_matrix(PDF *p, PDF_matrix m);
  192. void PDF_set_text_pos(PDF *p, float x, float y);
  193. void PDF_set_char_spacing(PDF *p, float spacing);
  194. void PDF_set_word_spacing(PDF *p, float spacing);
  195. void PDF_continue_text(PDF *p, char *text);
  196.  
  197. /* p_gstate.c */
  198. void PDF_save(PDF *p);
  199. void PDF_restore(PDF *p);
  200. void PDF_translate(PDF *p, float tx, float ty);
  201. void PDF_scale(PDF *p, float sx, float sy);
  202. void PDF_rotate(PDF *p, float phi);
  203.  
  204. void PDF_setdash(PDF *p, float d1, float d2);
  205. void PDF_setpolydash(PDF *p, float *darray, int length);
  206. void PDF_setflat(PDF *p, float flat);
  207. void PDF_setlinejoin(PDF *p, byte join);
  208. void PDF_setlinecap(PDF *p, byte cap);
  209. void PDF_setmiterlimit(PDF *p, float miter);
  210. void PDF_setlinewidth(PDF *p, float width);
  211.  
  212. /* p_color.c */
  213. /* do not use color operators within path objects */
  214. void PDF_setgray_fill(PDF *p, float g);
  215. void PDF_setgray_stroke(PDF *p, float g);
  216. void PDF_setgray(PDF *p, float g);
  217. void PDF_setrgbcolor_fill(PDF *p, float red, float green, float blue);
  218. void PDF_setrgbcolor_stroke(PDF *p, float red, float green, float blue);
  219. void PDF_setrgbcolor(PDF *p, float red, float green, float blue);
  220.  
  221. /* p_draw.c */
  222. void PDF_moveto(PDF *p, float x, float y);
  223. void PDF_lineto(PDF *p, float x, float y);
  224. void PDF_curveto(PDF *p, float x1, float y1, float x2, float y2, float x3, float y3);
  225. void PDF_circle(PDF *p, float x, float y, float r);
  226. void PDF_arc(PDF *p, float x, float y, float r, float alpha1, float alpha2);
  227. void PDF_rect(PDF *p, float x, float y, float width, float height);
  228. void PDF_closepath(PDF *p);
  229.  
  230. void PDF_stroke(PDF *p);
  231. void PDF_closepath_stroke(PDF *p);
  232. void PDF_fill(PDF *p);
  233. void PDF_fill_stroke(PDF *p);
  234. void PDF_closepath_fill_stroke(PDF *p);
  235. void PDF_endpath(PDF *p);
  236.  
  237. void PDF_clip(PDF *p);
  238.  
  239. /* p_image.c */
  240. void PDF_place_image(PDF *p, PDF_image *image, float x, float y, float scale);
  241. void PDF_place_inline_image(PDF *p, PDF_image *image, float x, float y, float scale);
  242. void PDF_put_image(PDF *p, PDF_image *image);
  243. void PDF_execute_image(PDF *p, PDF_image *image, float x, float y, float scale);
  244. void PDF_close_image(PDF *p, PDF_image *image);
  245.  
  246. /* p_jpeg.c */
  247. PDF_image *PDF_open_JPEG(PDF *p, char *filename);
  248. void PDF_close_JPEG(PDF *p, PDF_image *image);
  249.  
  250. /* p_tiff.c */
  251. PDF_image *PDF_open_TIFF(PDF *p, char *filename);
  252. void PDF_close_TIFF(PDF *p, PDF_image *image);
  253.  
  254. /* p_gif.c */
  255. PDF_image *PDF_open_GIF(PDF *p, char *filename);
  256. void PDF_close_GIF(PDF *p, PDF_image *image);
  257.  
  258. /* p_filter.c */
  259. void PDF_data_source_from_buf(PDF *p, PDF_data_source *src, byte *buffer, long len);
  260.  
  261. /* p_font.c */
  262. float PDF_stringwidth(PDF *p, byte *text);
  263.  
  264. /* p_hyper.c */
  265. void PDF_add_outline(PDF *p, char *text);
  266.  
  267. #endif                /* PDF_H */
  268.